package com.shiwaixiangcun.customer.adapter;

import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseSectionQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.SectionEntity;
import com.shiwaixiangcun.customer.R;
import com.shiwaixiangcun.customer.entity.DeviceData;

import java.util.List;

/**
 * Author   Administrator
 * Date     2017/12/22
 * Desc     eg
 *
 * @author Administrator
 */

public class AdapterSmartDevice extends BaseSectionQuickAdapter<AdapterSmartDevice.DeviceSection, BaseViewHolder> {


    public AdapterSmartDevice(List<DeviceSection> data) {
        super(R.layout.item_layout_device, R.layout.item_layout_myticket_header, data);
    }

    @Override
    protected void convertHead(BaseViewHolder helper, DeviceSection item) {
        if (item.isHeader) {
            helper.setText(R.id.tv_invalid, item.strHeader);
        }

    }

    @Override
    protected void convert(BaseViewHolder helper, DeviceSection item) {
        DeviceData dataBean = item.dataBean;
        helper.setText(R.id.tv_device_title, dataBean.getTitle());
        helper.setText(R.id.tv_device_info, dataBean.getInfo());
        ImageView iv = helper.getView(R.id.iv_flag);
        Glide.with(mContext).load(dataBean.getCover()).into(iv);
        if (dataBean.getId() == 2) {
            helper.getView(R.id.iv_arrow).setVisibility(View.VISIBLE);
            helper.getView(R.id.iv_cover).setVisibility(View.GONE);
        }

    }

    public void addData(List<DeviceSection> data) {
        this.mData.addAll(data);
        notifyDataSetChanged();
    }

    public void clearData() {
        this.mData.clear();
        notifyDataSetChanged();
    }

    public static final class DeviceSection extends SectionEntity<DeviceData> {

        private String strHeader;
        private DeviceData dataBean;

        public DeviceSection(boolean isHeader, String header) {
            super(isHeader, header);
            this.isHeader = true;
            strHeader = header;

        }

        public DeviceSection(DeviceData midwayLine) {
            super(midwayLine);
            this.dataBean = midwayLine;
        }
    }
}
